<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
    <#include "/common/elibs.html">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
</head>
<body>
<div class="x-body">
    <form class="layui-form">
        <input type="hidden" name="idxProAdmin" id="idxProAdmin" value="${id}"/>
        <input type="hidden" name="idProTransmission" id="idProTransmission"/>
        <div class="layui-form-item">
            <label class="layui-form-label">
                开始时间
            </label>
            <div class="layui-input-inline">
                <input type="text" id="beginTime" name="beginTime"
                       autocomplete="off" class="layui-input" disabled style="background-color: #b7b1b1;">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                结束时间
            </label>
            <div class="layui-input-inline">
                <input type="text" id="endTime" name="endTime"
                       autocomplete="off" class="layui-input" disabled style="background-color: #b7b1b1;">
            </div>
        </div>

        <div class="layui-form-item" id="difference">
            <label class="layui-form-label">
                距离结束时间天数
            </label>
            <div class="layui-input-inline">
                <input type="text" id="differenceTime" name="differenceTime"
                       autocomplete="off" class="layui-input" disabled style="background-color: #b7b1b1;">
            </div>
        </div>

        <div class='layui-col-md6 powerSupply' style='width: 100%;'>
            <div class='layui-card'>
                <div class="layui-form-item">
                    <label for="idxSysFilesListFile1" class="layui-form-label">
                        <span class="x-red">*</span>送电申请书：<br/>
                    </label>
                    <div class="layui-input-inline" >
                        <a><img class="layui-upload-img" src="" id="imgUrl1"  width="100px"/></a>
                        <br><br><br>
                        <input type="hidden" name="idxSysFilesListFile" id="idxSysFilesListFile1" >
                        <button type="button" class="layui-btn" id="upload1">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload1","imgUrl1","idxSysFilesListFile1");
                        </script>

                        <br>
                        <a><img class="layui-upload-img" src="" id="imgUrl2" width="100px"/></a>
                        <br><br><br>
                        <input type="hidden" name="idxSysFilesListFile" id="idxSysFilesListFile2"   >
                        <button type="button" class="layui-btn" id="upload2">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload2","imgUrl2","idxSysFilesListFile2");
                        </script>

                        <br>
                        <a><img class="layui-upload-img" src="" id="imgUrl3" width="100px"/></a>
                        <br><br><br>
                        <input type="hidden" name="idxSysFilesListFile" id="idxSysFilesListFile3"   >
                        <button type="button" class="layui-btn" id="upload3">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload3","imgUrl3","idxSysFilesListFile3");
                        </script>

                        <br>
                        <a><img class="layui-upload-img" src="" id="imgUrl4" width="100px"/></a>
                        <br><br><br>
                        <input type="hidden" name="idxSysFilesListFile" id="idxSysFilesListFile4"   >
                        <button type="button" class="layui-btn" id="upload4">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload4","imgUrl4","idxSysFilesListFile4");
                        </script>
                    </div>
                </div>
            </div>
        </div>

        <div class='layui-col-md6 powerSupply' style='width: 100%;'>
            <div class='layui-card'>
                <div class="layui-form-item">
                    <label for="commissioningApproval1" class="layui-form-label">
                        <span class="x-red">*</span>设备投运批准书：<br/>
                    </label>
                    <div class="layui-input-inline" >
                        <a><img class="layui-upload-img" src="" id="imgUrl5" width="100px"/></a>
                        <br><br><br>
                        <input type="hidden" name="commissioningApproval" id="commissioningApproval1" >
                        <button type="button" class="layui-btn" id="upload5">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload5","imgUrl5","commissioningApproval1");
                        </script>
                        <br>
                        <a><img class="layui-upload-img" src="" id="imgUrl6" width="100px"/></a>
                        <br><br><br>
                        <input type="hidden" name="commissioningApproval" id="commissioningApproval2"   >
                        <button type="button" class="layui-btn" id="upload6">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload6","imgUrl6","commissioningApproval2");
                        </script>
                        <br>

                        <img class="layui-upload-img" src="" id="imgUrl7" /><br><br><br>
                        <input type="hidden" name="commissioningApproval" id="commissioningApproval3"   >
                        <button type="button" class="layui-btn" id="upload7">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload7","imgUrl7","commissioningApproval3");
                        </script>
                        <br>
                        <a><img class="layui-upload-img" src="" id="imgUrl8" width="100px"/></a>
                        <br><br><br>
                        <input type="hidden" name="commissioningApproval" id="commissioningApproval4"   >
                        <button type="button" class="layui-btn" id="upload8">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload8","imgUrl8","commissioningApproval4");
                        </script>
                    </div>
                </div>
            </div>
        </div>


        <div class='layui-col-md6 powerSupply' style='width: 100%;'>
            <div class='layui-card'>
                <div class="layui-form-item">
                    <label for="accessNetworkApproval1" class="layui-form-label">
                        <span class="x-red">*</span>加入电网批准书：<br/>
                    </label>
                    <div class="layui-input-inline" >
                        <a><img class="layui-upload-img" src="" id="imgUrl9" width="100px"/></a>
                        <br><br><br>
                        <input type="hidden" name="accessNetworkApproval" id="accessNetworkApproval1" >
                        <button type="button" class="layui-btn" id="upload9">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload9","imgUrl9","accessNetworkApproval1");
                        </script>
                        <br>
                        <a><img class="layui-upload-img" src="" id="imgUrl10" width="100px"/></a>
                        <br><br><br>
                        <input type="hidden" name="accessNetworkApproval" id="accessNetworkApproval2"   >
                        <button type="button" class="layui-btn" id="upload10">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload10","imgUrl10","accessNetworkApproval2");
                        </script>

                        <br>
                        <a><img class="layui-upload-img" src="" id="imgUrl11" width="100px"/></a>
                        <br><br><br>
                        <input type="hidden" name="accessNetworkApproval" id="accessNetworkApproval3"   >
                        <button type="button" class="layui-btn" id="upload11">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload11","imgUrl11","accessNetworkApproval3");
                        </script>
                        <br>
                        <a><img class="layui-upload-img" src="" id="imgUrl12" width="100px"/></a>
                        <br><br><br>
                        <input type="hidden" name="accessNetworkApproval" id="accessNetworkApproval4"   >
                        <button type="button" class="layui-btn" id="upload12">
                            <i class="layui-icon">&#xe67c;</i>上传文件
                        </button>
                        <script>
                            updateFile("upload12","imgUrl12","accessNetworkApproval4");
                        </script>
                    </div>
                </div>
            </div>
        </div>




        <div class="layui-form-item" id="submitButton">
            <label for="" class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="preservation" type=button codeTyle="1" lay-submit="">
                保存
            </button>
            <button  class="layui-btn" lay-filter="preAdd" type=button codeTyle="2" lay-submit="">
                预提交
            </button>
            <button  class="layui-btn" lay-filter="add" type=button codeTyle="3" lay-submit="">
                提交
            </button>
        </div>
		<div class="layui-form-item" id="updateStart">
            <label for="" class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="update" type=button codeTyle="0" lay-submit="">
                修改
            </button>
        </div>
    </form>
</div>
<script>

    $(function(){
	var index = 43;
        getProTime($("#idxProAdmin").val(),40);
        ajaxFun('get','/pc/project/getPowerTransmissionStartUpInfo',{"idProAdmin":$("#idxProAdmin").val()},function(data){
            if(data.code != 0){
                alertFun(data);
            }else{
                if(data.data.submitState === 3){
                    $("#submitButton").hide();
                    $("#updateStart").show();
                    $("#difference").hide();
                }else{
                    $("#submitButton").show();
                    $("#updateStart").hide();
                }
                $("#idProTransmission").val(data.data.idProTransmission);
                for(var i=0;i<data.data.idxSysFilesListFile.length;i++){
                    $("#imgUrl"+(i+1)).attr("src",getIos(data.data.idxSysFilesListFile[i].suffixName,
                        data.data.idxSysFilesListFile[i].filePath));
                    $("#imgUrl"+(i+1)).parent().attr("href",data.data.idxSysFilesListFile[i].filePath);
                    $("#idxSysFilesListFile"+(i+1)).val(data.data.idxSysFilesListFile[i].fileId);
                }

                for(var i=0;i<data.data.commissioningApprovalListFile.length;i++){
                    $("#imgUrl"+(i+5)).attr("src",getIos(data.data.commissioningApprovalListFile[i].suffixName,
                        data.data.commissioningApprovalListFile[i].filePath));
                    $("#imgUrl"+(i+5)).parent().attr("href",data.data.commissioningApprovalListFile[i].filePath);
                    $("#commissioningApproval"+(i+1)).val(data.data.commissioningApprovalListFile[i].fileId);
                }

                for(var i=0;i<data.data.accessNetworkApprovalListFile.length;i++){
                    $("#imgUrl"+(i+9)).attr("src",getIos(data.data.accessNetworkApprovalListFile[i].suffixName,data.data.accessNetworkApprovalListFile[i].filePath));
                    $("#imgUrl"+(i+9)).parent().attr("href",data.data.accessNetworkApprovalListFile[i].filePath);
                    $("#accessNetworkApproval"+(i+1)).val(data.data.accessNetworkApprovalListFile[i].fileId);
                }
            }
        })
    })
    layui.use(['form','layer'], function() {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer, layedit = layui.layedit;

        //自定义验证规则
        form.verify({});

        //监听提交
        form.on('submit(add)', function (t) {
            addSubmit(3);
        });

        //监听保存
        form.on('submit(preservation)', function (t) {
            addSubmit(1);
        });

        //监听预提交
        form.on('submit(preAdd)', function (t) {
            addSubmit(2);
        });
		
		//修改
        form.on('submit(update)', function (t) {
            addSubmit(10);
        });
    });

    function addSubmit(submitState){
        var idxSysFilesListFile=new Array(),i = 0;
        $("input[name='idxSysFilesListFile']").each(function(){
            if(isNotNull($(this).val())) {
                var data = {
                    idSysFiles: $(this).val(),
                    resourcesType: 1
                };
                idxSysFilesListFile[i] = data;
                i++;
            }
        })

        var commissioningApproval=new Array(),i = 0;
        $("input[name='commissioningApproval']").each(function(){
            if(isNotNull($(this).val())) {
                var data = {
                    idSysFiles: $(this).val(),
                    resourcesType: 2
                };
                commissioningApproval[i] = data;
                i++;
            }
        })

        var accessNetworkApproval=new Array(),i = 0;
        $("input[name='accessNetworkApproval']").each(function(){
            if(isNotNull($(this).val())) {
                var data = {
                    idSysFiles: $(this).val(),
                    resourcesType: 3
                };
                accessNetworkApproval[i] = data;
                i++;
            }
        })
        var params = {
            //tcaDescribe : layui.layedit.getContent(index),
            "idProAdmin": $("#idxProAdmin").val(),
            "idProTransmission": $("#idProTransmission").val(),
            "idxSysFilesListFile": idxSysFilesListFile,
            "commissioningApprovalListFile": commissioningApproval,
            "accessNetworkApprovalListFile": accessNetworkApproval,
            "submitState":submitState
        }
        if (true) {
            ajaxFunJson('post','/pc/project/updatePowerTransmissionStartUp',JSON.stringify(params),function(data){
                if (data.code != 0) {
                    alertFun(data);
                } else {
                    window.location.href = path + "/modules/project/threePro/sdqd/list.html";
                    console.log("success !");
                }
            })

            return false;
        }
    }
</script></body></html>